import { Component, Vue } from 'vue-property-decorator';

/**
 * 这是一个列表公用业务逻辑处理的mixin类
 *
 *
 * @export
 * @class mixinTableOperation
 * @extends {Vue}
 */
@Component({
})
export class mixinTableOperation extends Vue {
    /**
     * 点击编辑类按钮时
     * 须同时引入mixinDialogFormParent
     * @param {*} { row } 数据
     * @param {string} { dialogName }
     * @memberof mixinTableOperation
     */
    onEditClick({ row }: any, dialogName?: string) {
        const me = this as any;
        me.showWin(true, row, dialogName);
    }

    // 删除弹窗配置
    deleteDialog: any = {
        // 删除标题
        title: '提示',
        // 删除提示文案
        name: "确定删除吗？",
        // 确认按钮名称
        comfirm: "删除"
    }

    /**
     * 点击删除按钮
     * 显示删除弹窗
     *
     * @param {*}
     * @memberof mixinTableOperation
     */
    onDelClick({ row }: any) {
        const me = this as any, dialog = me.deleteDialog;
        me.$confirm(
            dialog.name,
            dialog.title,
            {
                customClass: "message-el",
                confirmButtonText: dialog.comfirm,
                cancelButtonText: "取消",
                showClose: false,
                closeOnClickModal: false
            }
        )
            .then(() => {
                // 调用删除接口
                // 需要在methods中定义itemDel，必须返回Promise对象
                me.itemDel(row).then(() => {
                    me.delSuccess && me.delSuccess();
                    // 重新加载数据
                    me.loadView({ isDel: true });
                });
            })
            .catch(() => { });
    }

  
    /**
     * 改变数据状态
     * 需配置status方法
     *
     * @param {*} id
     * @param {string} tip
     * @param {string} title
     * @memberof mixinGridOperation
     */
    confirmMsg(params: any, tip: string, title: string = '提示', item: number = 1, goUrl: string = '') {
        const me = this as any;
        me.$confirm(`您将${tip}，是否继续？`, `${title}`, {
            confirmButtonClass: "btn-blue"
        }).then(() => {
            // confirmAction 是固定的方法，在视图中需要固定配置
            // 例如  @Action("departStatus") confirmAction: any;
            if (item == 1) {
                me.confirmAction(params).then(() => {
                    if (goUrl !== '') {
                        me.go(goUrl);
                    } else {
                        me.loadView();
                    }
                });
            } else if (item == 2) {
                me.confirmAction2(params).then(() => {
                    if (goUrl !== '') {
                        me.go(goUrl);
                    } else {
                        me.loadView();
                    }
                });
            } else if (item == 3) {
                me.confirmAction3(params).then(() => {
                    if (goUrl !== '') {
                        me.go(goUrl);
                    } else {
                        me.loadView();
                    }
                });
            }            
        }).catch(() => {
            me.changeFailure && me.changeFailure();
        });
    }


    download(params: any) {
        const me = this as any;
         // 例如  @Action("departStatus") downloadAction: any;
        me.downloadAction(params).then(() => {
           // me.loadView();
        }).catch(() => {
            me.changeFailure && me.changeFailure();
        });
    }
}
